package com.jzo2o.foundations.controller.operation;







import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.mysql.utils.PageHelperUtils;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-16
 */
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Resource  //根据名称注入
    private IServeService serveService;

    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        PageResult<ServeResDTO> page = serveService.page(servePageQueryReqDTO);
        return page;
    }


    @PostMapping("/batch")
    @ApiOperation("区域服务批量新增")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList) {
        serveService.batchAdd(serveUpsertReqDTOList);
    }

    /**
     * 区域服务上架
     * @param id
     */

    @ApiOperation("区域服务上架")
    @PutMapping("/onSale/{id}")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "服务id", required = true, dataType = "Long", paramType = "path")})
    public void onSale(@PathVariable("id") Long id) {
        serveService.onSale(id);
    }

    /**
     * 修改价格
     * @param id
     * @param price
     */
    @ApiOperation("修改价格")
    @PutMapping("/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataType = "Long", paramType = "path"),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataType = "Long", paramType = "query")
    })
    public void updatePrice(@PathVariable("id") Long id, @RequestParam("price") Double price) {
        serveService.updatePrice(id, price);
    }

    @ApiOperation("区域服务删除")
    @DeleteMapping("/{id}")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "服务id", required = true, dataType = "Long", paramType = "path")})
    public void delete(@PathVariable("id") Long id) {
        serveService.deleteById(id);
    }




}
